//
//  ViewController.m
//  TestLeak
//
//  Created by mac on 2025/8/30.
//

#import "ViewController.h"

@implementation ViewController {
   // NSMutableString *_buffer;
    NSTimer *timer;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    self.buffer = [NSMutableString string];
}


- (void)setRepresentedObject:(id)representedObject {
    [super setRepresentedObject:representedObject];

    // Update the view, if already loaded.
}

- (IBAction)startClick:(id)sender {
    __weak typeof(self) weakSelf = self;
    
    for (int i=0; i<100; i++) {
        timer = [NSTimer scheduledTimerWithTimeInterval:0.001 repeats:YES block:^(NSTimer * _Nonnull timer) {
            NSString *str = [[NSString alloc] initWithFormat:@"这是新建的字符串%@", @"Do any additional setup after loading the view."];
            [weakSelf.buffer appendString:str];
            
            if (weakSelf.buffer.length > 1000) {
                [weakSelf.buffer setString:@""];
            }
            NSLog(@"当前缓存：%@", weakSelf.buffer);
        }];
    
    }
}

- (IBAction)stopClick:(id)sender {
    [timer invalidate];
}


@end
